﻿using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.ComponentModel.DataAnnotations;

namespace HobSoft.SoccerBet2014.Domain.Models
{
    using Core;
    using KeyHelper;
    [Serializable]
    [DataContract]
    public class Market : IModel
    {
        public Market()
        {
            OddsIDS = new List<string>();
        }

        [PrimaryKey]
        [DataMember(IsRequired = true)]
        public string Key
        {
            get { return KeyGenerateHelper.Create<Market>(this); }
            set { ; }
        }

        private byte _bmId;
        [Key]
        [DataMember(IsRequired = true)]
        public byte BmID
        {
            get { return _bmId; }
            set { _bmId = value; }
        }

        private string _gameID;
        [Key]
        [MaxLength(50)]
        [MinLength(1)]
        [DataMember(IsRequired = true)]
        public string GameID
        {
            get { return _gameID; }
            set { _gameID = value; }
        }

        private string _host;
        [Required]
        [MaxLength(200)]
        [MinLength(2)]
        [DataMember(IsRequired = true)]
        public string Host
        {
            get { return _host; }
            set { _host = value; }
        }

        private string _updateAccount;
        [Required]
        [MaxLength(50)]
        [MinLength(2)]
        [DataMember(IsRequired = true)]
        public string UpdateAccount
        {
            get { return _updateAccount; }
            set { _updateAccount = value; }
        }

        private DateTime _updateTime;
        [Required]
        [DataMember(IsRequired = true)]
        public DateTime UpdateTime
        {
            get { return _updateTime; }
            set { _updateTime = value; }
        }

        private IList<string> _oddsIds;
        [Required]
        [DataMember]
        public IList<string> OddsIDS
        {
            get { return _oddsIds; }
            set { _oddsIds = value; }
        }

        [IgnoreDataMember]
        public string OddsIDSString
        {
            get { return string.Join(",", OddsIDS); }
            set
            {
                if (string.IsNullOrEmpty(value))
                    return;
                var _oddsIds = value.Split(',');
                OddsIDS = new List<string>(_oddsIds);
            }
        }


    }
}
